home *** CD-ROM | disk | FTP | other *** search
/ Clickx 96 / Clickx 96.iso / software / tools / tool / xbmc-10.1.exe / addons / script.module.pil / lib / PIL / XVThumbImagePlugin.py < prev   
Encoding:
Python Source  |  2009-04-06  |  1.8 KB  |  74 lines

  1. #
  2. # The Python Imaging Library.
  3. # $Id$
  4. #
  5. # XV Thumbnail file handler by Charles E. "Gene" Cash
  6. # (gcash@magicnet.net)
  7. #
  8. # see xvcolor.c and xvbrowse.c in the sources to John Bradley's XV,
  9. # available from ftp://ftp.cis.upenn.edu/pub/xv/
  10. #
  11. # history:
  12. # 98-08-15 cec  created (b/w only)
  13. # 98-12-09 cec  added color palette
  14. # 98-12-28 fl   added to PIL (with only a few very minor modifications)
  15. #
  16. # To do:
  17. # FIXME: make save work (this requires quantization support)
  18. #
  19.  
  20. __version__ = "0.1"
  21.  
  22. import string
  23. import Image, ImageFile, ImagePalette
  24.  
  25. # standard color palette for thumbnails (RGB332)
  26. PALETTE = ""
  27. for r in range(8):
  28.     for g in range(8):
  29.         for b in range(4):
  30.             PALETTE = PALETTE + (chr((r*255)/7)+chr((g*255)/7)+chr((b*255)/3))
  31.  
  32. ##
  33. # Image plugin for XV thumbnail images.
  34.  
  35. class XVThumbImageFile(ImageFile.ImageFile):
  36.  
  37.     format = "XVThumb"
  38.     format_description = "XV thumbnail image"
  39.  
  40.     def _open(self):
  41.  
  42.         # check magic
  43.         s = self.fp.read(6)
  44.         if s != "P7 332":
  45.             raise SyntaxError, "not an XV thumbnail file"
  46.  
  47.         # Skip to beginning of next line
  48.         self.fp.readline()
  49.  
  50.         # skip info comments
  51.         while 1:
  52.             s = self.fp.readline()
  53.             if not s:
  54.                 raise SyntaxError, "Unexpected EOF reading XV thumbnail file"
  55.             if s[0] != '#':
  56.                 break
  57.  
  58.         # parse header line (already read)
  59.         s = string.split(s.strip())
  60.  
  61.         self.mode = "P"
  62.         self.size = int(s[0]), int(s[1])
  63.  
  64.         self.palette = ImagePalette.raw("RGB", PALETTE)
  65.  
  66.         self.tile = [
  67.             ("raw", (0, 0)+self.size,
  68.              self.fp.tell(), (self.mode, 0, 1)
  69.              )]
  70.  
  71. # --------------------------------------------------------------------
  72.  
  73. Image.register_open("XVThumb", XVThumbImageFile)
  74.